package com.qire.manhua.dialog;

import android.os.Bundle;
import android.view.Gravity;
import android.view.LayoutInflater;
import android.view.View;
import android.view.Window;
import android.view.WindowManager;

import com.qire.common.basic.ObjectUtil;
import com.qire.common.support.base.BaseActivity;
import com.qire.common.support.base.BaseDialog;
import com.qire.manhua.R;
import com.qire.manhua.databinding.DialogPayWaySelectorOfBuyVipBinding;

import androidx.annotation.NonNull;

/**
 * 支付方式选择器弹窗：在会员充值购买时弹出
 */
public class PayWaySelectorOfBuyVipDialog extends BaseDialog {

    private final DialogPayWaySelectorOfBuyVipBinding bindingView;

    private final View.OnClickListener paymentMethodListener;

    public PayWaySelectorOfBuyVipDialog(BaseActivity activity, @NonNull View.OnClickListener listener) {
        super(activity, R.style.CustomDialog_Translucent);
        this.paymentMethodListener = listener;

        this.bindingView = DialogPayWaySelectorOfBuyVipBinding.inflate(LayoutInflater.from(activity));
        bindingView.setPayWaySelectorOfBuyVipDialog(this);
    }

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(bindingView.getRoot());
        setGravityCenter();
        setCancelable(true);
    }

    private void setGravityCenter() {
        Window window = getWindow();
        window.setGravity(Gravity.CENTER);
        WindowManager.LayoutParams params = window.getAttributes();
        params.width = WindowManager.LayoutParams.MATCH_PARENT;
        params.height = WindowManager.LayoutParams.MATCH_PARENT;
        window.setAttributes(params);
    }

    public void closeBtnOnClick(View view){
        dismiss();
    }

    public void paymentMethodOnClick(View view){
        if(ObjectUtil.nonNull(paymentMethodListener)) {
            paymentMethodListener.onClick(view);
        }
        dismiss();
    }

}
